/**
 * 未登录主界面需要的JavaScript验证
 */

layui.use('element', function() {
	var element = layui.element;
});

$("#otheruserName").click(function() {
	var userName = $("#otheruserName").text();
	window.location.href = "/user/otheruserhome.do?userName=" + userName;
});

layui.use('layer', function() {
	var layer = layui.layer;
	$('span#praise').click(function() {
		layer.alert('请先登录哦', function(index){
			  layer.close(index);
			}); 
	});
	$('span#tread').click(function() {
		layer.alert('请先登录哦', function(index){
			  layer.close(index);
			}); 
	});
	$('span#comment').click(function() {
		layer.alert('请先登录哦', function(index){
			  layer.close(index);
			}); 
	});
	$('span#validity').click(function() {
		layer.alert('请先登录哦', function(index){
			  layer.close(index);
			}); 
	});
	
	/**********************************************************/
	$("#Bsearch").click(function(){
	    layer.open({
	        type: 1
	        ,title: false
	        ,closeBtn: false
	        ,shadeClose: true
	        ,maxWidth: 10000
	        ,skin: 'fly-layer-search'
	        ,content: ['<form action="/common/search.do">'
	          ,'<input autocomplete="off" placeholder="搜索内容，回车跳转" type="text" name="searchtext">'
	        ,'</form>'].join('')
	        ,success: function(layero){
	          var input = layero.find('input');
	          input.focus();
	          layero.find('form').submit(function(){
	            var val = input.val();
	            if(val.replace(/\s/g, '') === ''){
	              return false;
	            }
	            input.val(input.val());
	        });
	        }
	      })
	});


	/*************************************分页（刷新分页实例）*******************************************/

	layui.use('laypage', function () {
		var laypage = layui.laypage;
		var category=$("#category").val();
		var orderby=$("#orderby").val();
		var totalCount=$("#TotalNumber").val();
		var currentPage=$("#page").val();
		//执行一个laypage实例
		laypage.render({
			elem: 'B_Page'
			, count:totalCount
			, limit: 20
			,curr: currentPage //获取起始页
			, first: '首页'
			, last: '尾页'
			, prev: '<em>←</em>'
			, next: '<em>→</em>'
			, skip: true
			, jump: function (obj, first) {
				if (!first) {
					window.location.href="/essay/essayreadselect.do?currentPage="+obj.curr+"&category="+category+
						"&orderby="+orderby;
				}
			}
		});
	});
});